package com.example.tang.zhayan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.tang.zhayan.R;
import com.example.tang.zhayan.bean.HomeGirlItem;
import com.example.tang.zhayan.utils.ImgOptionsUtils;
import com.squareup.picasso.Picasso;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by yang on 2015/12/15.
 */
public class HomeGirlItemAdapter extends BaseAbstractAdapter<HomeGirlItem> {

    private ImageOptions options;

    public HomeGirlItemAdapter(Context context, List<HomeGirlItem> list) {
        super(context, list);
        options = new ImageOptions.Builder()
                .setLoadingDrawableId(R.mipmap.default_loader_image1)
                .setFailureDrawableId(R.mipmap.default_loader_image1)
                .setCircular(true)
                .build();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_home_girl_layout, parent, false);
            holder = new ViewHolder();
            holder.middleIV = (ImageView) convertView.findViewById(R.id.middle_iv);
            holder.topIv = (ImageView) convertView.findViewById(R.id.top_iv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
            Picasso.with(context).load(list.get(position).getLogo()).placeholder(R.mipmap.default_loader_image1).into(holder.middleIV);
//            Picasso.with(context).load(list.get(position).getHead()).placeholder(R.mipmap.default_loader_image1).into(holder.topIv);
                x.image().bind(holder.topIv,list.get(position).getHead(),options);
        }
        return convertView;
    }

    class ViewHolder {
        ImageView middleIV;
        ImageView topIv;
    }
}
